home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSERROR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-11
|
8KB
|
277 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bserror.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains error handling routines. There are two primary entry
// points:
// Error() displays a message and returns FALSE.
// Fatal() displays a message and exits.
//
// Both functions rely on DebugSetLocation() having been called. The error
// functions can use an external function to display the message.
//
// The first paramters to the error functions can be either an error number
// (< 0xFFFF) or a pointer to a string. In either case, a variable number of
// parameters may be passed. Normally, low-level error which occur very
// infrequently use hard coded error strings while higher level messages
// use external messages.
//
// Error messages are written to the program log file if the log level is
// >= 1 and file logging is enabled!
//
// Error message text should not exceed 1024 bytes in length.
//
// Error messages are display using a display function. A user supplied
// function may be registered, otherwise a default function is used.
//
// External error display function should return non-zero if display failed.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Prototypes
//----------------------------------------------------------------------------
static SHORT FN_E ErrorDisplay(PCSZ);
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
static PFNERR pfnerr = ErrorDisplay;
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_EV Error_Debug(PCSZ psz, ...)
{
va_list marker;
va_start(marker,psz);
ErrorV_Debug(psz, marker);
va_end(marker);
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Default error display function. Simply writes to standard
// out using the base library output routines.
// Parameters: pcsz Message to display.
// Returns: 1
//----------------------------------------------------------------------------
static SHORT FN_E ErrorDisplay(PCSZ pcsz)
{
#if OS_WINDOWS
MessageBox(NULL, pcsz, "ERROR !", MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL);
#else
OutputZ("\nERROR!\n");
OutputZ(pcsz);
OutputZ("\n\n");
#endif
return 1;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_EV ErrorNoMem_Debug(PCSZ pcsz, SIZET cLine)
{
DebugSetLocation((PSZ)pcsz, cLine);
Error_Debug(
"Out of memory.\n"
"Please increase available system memory and try again.");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Set the error display function.
// This function should return non-zero if successful.
// Parameters: pfnerr New error display function.
// If null, the default function is installed.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E ErrorSetDisplay(PFNERR _pfnerr)
{
if (_pfnerr == NULL)
_pfnerr = ErrorDisplay;
pfnerr = _pfnerr;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Display an error message
// Internal function used to format message text.
// Parameters: pcsz Error message text
// marker Variable length argument list
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_E ErrorV_Debug(PCSZ pcsz, va_list marker)
{
static BOOL afRecurse[MAX_THREADS];
CHAR szFormat[IOBUF_SIZE];
PSZ pszOut;
USHORT us1, us2;
PSZ pszMsg = NULL;
BOOL fFormat = TRUE;
if (afRecurse[THREADID - 1]) // Recursing!!!
return FALSE;
afRecurse[THREADID - 1] = TRUE;
DebugContext(szFormat, FALSE); // Get context
pszOut = strchr(szFormat, '\0');
us1 = P2US1(pcsz);
us2 = P2US2(pcsz);
if (!us2)
{
CHAR szName[30];
sprintf(szName, "ERROR%05u~STRING", us1);
if (!CfgFind(szName)
|| !CfgRead(szName, (PBYTE _FAR_ *)&pszMsg, NULL))
{
sprintf(pszOut, "Unkown error # %u.", us1);
fFormat = FALSE;
}
else
pcsz = pszMsg;
}
if (fFormat) // Format the message
vsprintf(pszOut, pcsz, marker);
if (pszMsg) // Free text buffer
MemFree(pszMsg);
// Verify length
if (strlen(szFormat) >= sizeof(szFormat))
Halt("Fatal internal buffer overflow.\nPlease contact customer service.");
if ((*pfnerr)(szFormat) == 0) // Display
ErrorDisplay(szFormat);
Log_DebugV(1, pcsz, marker); // Write to log file
afRecurse[THREADID - 1] = FALSE;
return FALSE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: FALSE.
//----------------------------------------------------------------------------
BOOL FN_EV Fatal_Debug(PCSZ psz, ...)
{
va_list marker;
va_start(marker,psz);
ErrorV_Debug(psz, marker);
va_end(marker);
exit(99);
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Invalid function call message.
// Parameters: pcsz Function name
// Returns: FALSE
//----------------------------------------------------------------------------
BOOL FN_E Invalid_Debug(PCSZ pcsz)
{
CHAR szBuffer[160];
sprintf(szBuffer, "Invalid or unimplemented function call - '%s'.", pcsz);
Fatal_Debug(szBuffer);
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Functionality not implemented
// Parameters: pcsz Function name
// Returns: FALSE
//----------------------------------------------------------------------------
BOOL FN_E NotImplemented_Debug(PCSZ pcsz)
{
CHAR szBuffer[160];
if (pcsz == NULL)
pcsz = "I'm sorry, that";
sprintf(szBuffer, "%s is not implemented.", pcsz);
Error_Debug(szBuffer);
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN ErrorTest(SHORT sTest)
{
Error((PSZ)1);
Error((PSZ)0xFFFF); // Non-existing error number
Error("This is a %s error", "normal");
if (sTest == 1)
Fatal("This is a %s error", "fatal");
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------